package com.sky.service.impl;

import com.sky.result.Result;
import com.sky.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class ShopServiceImpl implements ShopService {

    @Autowired
    private StringRedisTemplate redisTemplate;
    private final static String key = "SHOP_STATUS";
    /**
     * 设置店铺营业状态
     *
     * @param status
     * @return
     */
    @Override
    public Result setStatus(Integer status) {
        redisTemplate.opsForValue().set(key,status+"");
        return Result.success();
    }

    /**
     * 获取店铺营业状态
     * @return
     */
    @Override
    public Result getStatus() {
        String status = redisTemplate.opsForValue().get(key);
        if (status == null){
            setStatus(1);
        }
        return Result.success(Integer.parseInt(status));
    }
}
